<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <title>编辑销售类型</title>
  <script type="text/javascript">
      Ext.onReady(function () {
          var saleTypeId = Ext.create('Ext.form.field.Hidden', {
              name: 'id'
          });

          var companies = Ext.create('Ext.form.ComboBox', {
              fieldLabel: '所属公司',
              store: companyAllInfoStore,
              allowBlank: false,
              blankText: "公司必须选择",
              emptyText: '请选择...',
              valueField: 'id',
              displayField: 'name',
              name: 'company_id',
              loadingText: '搜索中...',
              minChars: 0,
              anchor: '100%',
              listConfig: {
                  loadingText: 'Searching...',
                  getInnerTpl: function () {
                      return '{name}';
                  }
              }
          });

          var name = Ext.create('Ext.form.field.Text', {
              fieldLabel: '名称',
              allowBlank: false,
              blankText: "销售类型名称不能为空",
              name: 'name',
              anchor: '100%'
          });

          var ab = Ext.create('Ext.form.field.Text', {
              fieldLabel: '缩写',
              allowBlank: false,
              blankText: "销售类型名称不能为空",
              name: 'ab',
              anchor: '100%'
          });

          var discount = Ext.create('Ext.form.field.Number', {
              fieldLabel: '折扣',
              name: "discount",
              allowBlank: false,
              allowDecimals: true,
              minValue: 0,
              maxValue: 2,
              minValue: 0,
              anchor: '100%',
              value: 1
          });

          var paymentPropotion = Ext.create('Ext.form.field.Number', {
              fieldLabel: '出货付款比例',
              name: "payment_propotion",
              allowBlank: false,
              allowDecimals: true,
              minValue: 0,
              maxValue: 1,
              minValue: 0,
              anchor: '100%',
              value: 1
          });

          var desc = Ext.create('Ext.form.TextArea', {
              fieldLabel: '描述',
              name: 'description',
              height: 80,
              anchor: '100%'
          });

          //提交按钮
          var submitButton = Ext.create('Ext.Button', {
              text: '提交',
              iconCls: 'icon-save',
              handler: function () {
                  if (editSaleTypeForm.form.isValid()) {
                      editSaleTypeForm.form.submit({
                          method: 'GET',
                          success: function (result, response) {
                              if (response.result.info == "成功") {
                                  //添加成功后，隐藏窗口，并刷新Grid
                                  editSaleTypeWin.destroy();
                              }
                              else {
                                  Ext.MessageBox.alert('消息', response.result.info);
                              }
                          },
                          failure: function (result, response) {
                              Ext.MessageBox.alert('提示', result.responseText);
                          }
                      });
                  }
                  else {
                      Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                  }
              }
          })

          //暂时保存按钮
          var closeButton = Ext.create('Ext.Button', {
              text: '关闭',
              tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
              iconCls: 'exit',
              handler: function () {
                  editSaleTypeWin.destroy();
              }
          });

          var editSaleTypeForm = Ext.create('Ext.form.Panel', {
              fieldDefaults: {
                  labelWidth: 80,
                  labelAlign: 'right'
              },
              frame: true,
              url: '/sale_type/update?id=' + saleTypeId,
              reader: Ext.create('Ext.data.reader.Json', {
                  model: 'SaleType',
                  root: 'root'
              }),
              bodyStyle: 'padding:5px 5px 0',
              width: 310,
              //height:300,
              items: [saleTypeId, companies, name, ab, discount, paymentPropotion, desc],
              buttons: [submitButton, closeButton]
          });
          //编辑前，把数据引入到表单中。
          editSaleTypeForm.form.load({
              url: '/sale_type/getSaleTypeById?id=<%=params[:id]%>',
              method: 'GET',
              waitMsg: '正在载入数据...',
              success: function (form, action) {
              },
              failure: function (form, action) {
                  Ext.MessageBox.alert('提示信息', '信息加载失败');
              }
          });

          editSaleTypeForm.render('edit_sale_type_form');
      })
  </script>
</head>
<body>
<div id="edit_sale_type_form"></div>
</body>
</html>
